﻿using ASmile.Helpers;
using ASmile.ORM;
using ASmile.ORM.CodeBuilder.Builder;
using System;

namespace ASmile.ORM.CodeBuilder.Builder
{
    class BuilderFactory
    {        
        public static IBuilder Create(M_Config config)
        {
            if (!EnumHelper.StringToEnum<EmDbType>(config.DBType, out EmDbType t))
            {
                throw new NotSupportedException("错误的数据库类型");
            }
            IBuilder builder;
            switch (t)
            {
                case EmDbType.SQLServer:
                    builder = new BuilderSqlServer(config);
                    break;
                case EmDbType.SQLite:
                    builder = new BuilderSQLite(config);
                    break;
                case EmDbType.Oracle:
                    builder = new BuilderOracle(config);
                    break;
                case EmDbType.MySQL:
                    builder = new BuilderMySql(config);
                    break;
                default:
                    throw new NotSupportedException("不支持的数据库类型");
            }
            
            return builder;
        }
    }
}